<?php

/**
 * This is the model class for table "{{ROOM}}".
 *
 * The followings are the available columns in table '{{ROOM}}':
 * @property string $id
 * @property string $name
 * @property integer $id_server
 * @property integer $id_game
 * @property integer $port_vpn
 * @property integer $port_mnt
 * @property string $pwn_mnt
 *
 * The followings are the available model relations:
 * @property GAME $idGame
 * @property SERVER $idServer
 */
class ROOM extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return ROOM the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return '{{ROOM}}';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('name, id_server, id_game, port_vpn, port_mnt', 'required'),
			array('id_server, id_game, port_vpn, port_mnt', 'numerical', 'integerOnly'=>true),
			array('pwn_mnt', 'length', 'max'=>50),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, name, id_server, id_game, port_vpn, port_mnt, pwn_mnt', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'idGame' => array(self::BELONGS_TO, 'GAME', 'id_game'),
			'idServer' => array(self::BELONGS_TO, 'SERVER', 'id_server'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'name' => 'Name',
			'id_server' => 'Id Server',
			'id_game' => 'Id Game',
			'port_vpn' => 'Port Vpn',
			'port_mnt' => 'Port Mnt',
			'pwn_mnt' => 'Pwn Mnt',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id,true);
		$criteria->compare('name',$this->name,true);
		$criteria->compare('id_server',$this->id_server);
		$criteria->compare('id_game',$this->id_game);
		$criteria->compare('port_vpn',$this->port_vpn);
		$criteria->compare('port_mnt',$this->port_mnt);
		$criteria->compare('pwn_mnt',$this->pwn_mnt,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}